const models = require("../models/index.js");
const Manadger = models.Manadger;
const uuid = require("uuid");
const bcrypt = require("bcrypt");
class AdminService {
  async registrationManadger(email, password) {
    const candidate = await Manadger.findOne({ where: { email } });
    if (candidate) {
      throw new Error(`Пользователь с почтой ${email} уже существует`);
    }

    const hashPassword = await bcrypt.hash(password, 5);
    const activationLink = uuid.v4();
    const manadger = await Manadger.create({
      email,
      password: hashPassword,
      activationLink,
    });
    return { manadger };
  }
}

module.exports = new AdminService();
